package de.cbf.cam.dsa.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import de.cbf.cam.dsa.model.base.TalentTmpl;
import de.cbf.cam.dsa.model.entities.BattleChar;
import de.cbf.cam.dsa.model.entities.OneAction;
import de.cbf.cam.dsa.model.entities.maneuvers.OneManeuver;

public class ModelBattle {	
	
	private static ModelBattle instance= new ModelBattle();
	
	/**
	 * @uml.property  name="charactersInBattle"
	 * @uml.associationEnd  multiplicity="(0 -1)" elementType="de.cbf.cam.dsa.model.entities.BattleChar"
	 */
	private List<BattleChar> charactersInBattle = new ArrayList<BattleChar>();
		
	/**
	 * @uml.property  name="actions"
	 */
	private List<OneAction> actions = new ArrayList<OneAction>();	
	/**
	 * @uml.property  name="actionsSorted"
	 */
	private boolean actionsSorted;
	
	
	/**
	 * @uml.property  name="roundCount"
	 */
	private Integer roundCount=0;

	public static ModelBattle getInstance() {
		return instance;
	}
	
	public ModelBattle(){		
		
	}
//=============================================================================
	/**
	 * @return the charactersInBattle
	 */
	public List<BattleChar> getCharactersInBattle() {
		return charactersInBattle;
	}
	/**
	 * @return  the actionsSorted
	 * @uml.property  name="actionsSorted"
	 */
	public boolean isActionsSorted() {
		return actionsSorted;
	}
	/**
	 * @return  the roundCount
	 * @uml.property  name="roundCount"
	 */
	public Integer getRoundCount() {
		return roundCount;
	}
	/**
	 * @return the actions
	 */
	public List<OneAction> getActions() {
		return actions;
	}
	
	public List<TalentTmpl> getAllTalentTemplates() {		
		return ModelBase.getInstance().getAllTalentTemplates();
		
	}
	public List<OneManeuver> getAllManouvers() {
		return ModelBase.getInstance().getAllManeuvers();
	}

	
	
	/**
	 * @param roundCount  the roundCount to set
	 * @uml.property  name="roundCount"
	 */
	public void setRoundCount(Integer roundCount) {
		this.roundCount = roundCount;
	}
	/**
	 * @param charactersInBattle the charactersInBattle to set
	 */
	public void setCharactersInBattle(List<BattleChar> charactersInBattle) {
		this.charactersInBattle = charactersInBattle;
	}

	/**
	 * @param actions the actions to set
	 */
	public void setActions(List<OneAction> actions,boolean sorted) {
		this.actions = actions;
		this.actionsSorted = sorted;
	}

	public BattleChar getBattleCharacterByName(String characterName) {
		for (Iterator<BattleChar> iterator = charactersInBattle.iterator(); iterator.hasNext();) {
			BattleChar character = (BattleChar) iterator.next();
			if(character.getName().equalsIgnoreCase(characterName)){
				return character;
			}
		}
		return null;
	}

	
}
